package com.hsgene.user.constants;

/**
 * 用户类型
 *
 * @author wangbing
 * @version 1.0, 2018/10/16
 */
public enum UserIntType {

    /**
     * 运营管理人员
     */
    MANAGER(0, "运营管理人员"),

    /**
     * 地服
     */
    GROUND_SERVANT(1, "地服"),

    /**
     * 医生
     */
    DOCTOR(2, "医生"),

    /**
     * C端用户
     */
    CUSTOMER(3, "C端用户"),

    UNDEFINED(99, "未知类型");

    private final int value;

    private final String desc;

    public int getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    UserIntType(int value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public static UserIntType getEnum(int value) {
        for (UserIntType type : values()) {
            if (type.value == value) {
                return type;
            }
        }

        return UNDEFINED;
    }

    public static UserIntType getEnum(String value) {
        try {
            int code = Integer.valueOf(value);
            for (UserIntType type : values()) {
                if (type.value == code) {
                    return type;
                }
            }
        } catch (Exception e) {
            throw new IllegalStateException("非法用户类型:" + value);
        }

        return UNDEFINED;
    }
}
